import {Http} from "../utils/http.js";
import {Paging} from "../utils/paging.js";
import {config} from "../config/config.js";

class Plan{
	static background = ['#FFEBD5','#F0E2FF','#E6F5F2','#E6F1FF'];
	static linBackground = [
		['#6D39E9','#EBE7FF'],
		['#FC9E81','#FFF5E7'],
		['#81D4FF','#C6ECFF'],
	]
	static async getDatePlan(date){
		let res = (await Http.tSend({
			url:`/plan/findDayPlan`,
			data:{
				date
			}
		})).plans
		if(res && res.length>0){
			res.map((item,index)=>{
				item['bg_color']=this.background[index%4];
				item['line_color']=this.linBackground[index%3];
			})
		}
		return res;
	}
	static async getFindFriendAndPlan(date){
		let res = (await Http.tSend({
			url:'/plan/findFriendAndPlan',
			data:{
				date
			}
		})).frindAndPlans;
		let tabs = [];
		let plan = [];
		if(res) res.forEach((item,index)=>{
			tabs.push({
				name: item.friendName
			});
			plan.push(item.plans)
		})
		if(plan) plan.forEach(item=>{
			item.forEach((i,j)=>{
				i['bg_color']=this.background[j%4];
			})
		})
		return {tabs,plan};
	}
	static toTimeArray(data){
		if(!data)return;
		let res = {};
		for(let i=0;i<data.length;i++){
			let item = data[i];
			if(!res[item.startTime]){
				 res[item.startTime]=[item];
			}else{
				res[item.startTime] = res[item.startTime].concat(item);
			}
		}
		let result = [];
		for(let key in res){
			let item = { name:key,value:res[key]}
			result.push(item)
		}
		return result;
	}
	static async sendClockInPlan(planId){
		let res = (await Http.tSend({
			url:`/plan/clockInPlan`,
			method:"POST",
			data:{
				planId
			}
		}))
	
		return res;
	}
	static async sendRemindRemind(data){
		let res = (await Http.tSend({
			url:'/remind/remind',
			data:{
				data
			}
		}))
			
		return res;
	}
	static async getMyAllPlan(data){
		let res = (await Http.tSend({
			method:"POST",
			url:'/plan/findPlan',
		})).plans
			
		return res;
	}
	static async getPlanList(){
		let res = (await Http.tSend({
			method:"get",
			url:'/news/getPlanList',
		})).plans
			
		return res;
	}
	static async getPlanRecords(data){
		let res = (await Http.tSend({
			method:"get",
			url:'/plan/findPlanRecords',
			data
		})).item
		return res;
	}
	
}




export {
	Plan
}
